package com.socialcoco.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.socialcoco.entity.Comment;
import com.socialcoco.entity.Reply;
import com.socialcoco.exception.myExection;
import com.socialcoco.respone.BaseResponse;
import com.socialcoco.respone.ResultUtils;
import com.socialcoco.respone.resultenum;
import com.socialcoco.serviceImpl.ReplyServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 赵志浩
 * @since 2022-03-17 09:16:50
 */
@Slf4j
@RestController
@RequestMapping("/socialcoco/user")
public class ReplyController {
    /**、
     * 添加用户的回复
     */
    @Autowired
    private ReplyServiceImpl replyService;
    @ApiOperation("用户回复评论")
    @PostMapping("/saveCommentReply")
    public BaseResponse<Object> saveCommentReply(@RequestBody Reply reply, @RequestHeader("token")String token){
        //对传递过来的对象判断，然后返回自定义的错误异常
        if(reply==null){
            throw new myExection(resultenum.BODY_NULL.getCode(),resultenum.BODY_NULL.getMsg());
        }
        reply.setCreateTime(new Date());
        replyService.save(reply);
        return ResultUtils.success("commentOk");
    }
    /**
     * 显示用户回复的所有评论在和评论属于一对多，所以在显示所有评论的时候封装结果集显示出对应评论的所有回复
     */
}

